#!/usr/bin/python
# -*- coding: utf-8 -*-


from os import walk
import os

def makefilename2lower(path, exts=[], dir=False):
    if os.path.exists(path) is not True:
        ex = "path: %s not exist" % (path)
        raise Exception(ex)
    for (dirpath, dirnames, filenames) in walk(path):
        for filename in filenames:
            lowname = filename.lower()
            name, ext = os.path.splitext(lowname)
            if filename != lowname and (len(exts) == 0 or ext in exts):
                os.rename(
                    os.path.join(dirpath, filename),
                    os.path.join(dirpath, lowname))
        if dir is True:
            for dirname in dirnames:
                lowname = dirname.lower()
                if dirname != lowname:
                    os.rename(os.path.join(dirpath, dirname),
                    os.path.join(dirpath, lowname))

if __name__ == '__main__':
    makefilename2lower("/home/lu/test")


